package sw6.digipecs.database;

import android.database.Cursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQuery;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class PictureSituationIDCursor extends IDCursor {
	
	// TODO: Update all documentation
	
	public PictureSituationIDCursor(SQLiteDatabase db,
			SQLiteCursorDriver driver, String editTable, SQLiteQuery query) {
		super(db, driver, editTable, query);
		
		mIndexID = getColumnIndexOrThrow(DBAdapter.DB_PictureSituation_Picture_ID);
	}

	private static final String[] mColumns = { DBAdapter.DB_PictureSituation_Picture_ID };
	
	private static class Factory implements CursorFactory {
		@Override
		public Cursor newCursor(SQLiteDatabase db,
				SQLiteCursorDriver masterQuery, String editTable,
				SQLiteQuery query) {
			return new PictureSituationIDCursor(db, masterQuery, editTable, query);
		}
	}
		
	public static PictureSituationIDCursor queryActiveForSituation(SQLiteDatabase mDb, int situation) {
		final String select = DBAdapter.DB_PictureSituation_Active + " = " + DBAdapter.TRUE + " AND " + DBAdapter.DB_PictureSituation_Situation_ID + " = " + situation;
		return(PictureSituationIDCursor) mDb.queryWithFactory(new Factory(), true, DBAdapter.DB_PictureSituation, mColumns, select, null, null, null, DBAdapter.DB_PictureSituation_Position, null);
	}
	
	public static PictureSituationIDCursor queryForSituation(SQLiteDatabase mDb, int situation) {
		final String select = DBAdapter.DB_PictureSituation_Situation_ID + " = " + situation;
		return(PictureSituationIDCursor) mDb.queryWithFactory(new Factory(), true, DBAdapter.DB_PictureSituation, mColumns, select, null, null, null, DBAdapter.DB_PictureSituation_Position, null);
	}
}
